package com.atguigu.scala.chapter8

import scala.util.Random

/**
 * @author lizikuan
 * @date 2021/5/25 18:46
 */
object $07_PartialFunction {
  def main(args: Array[String]): Unit = {
    val arr  = Array("hello",10.0,22,false)
    val index = Random.nextInt(arr.length)
    val value = arr(index)


    val func:PartialFunction[Any,Int] ={
      case "hello" =>
        println("hello.......")
        10
      case 22 =>
        println("22.......")
        30
      case false => println("false.......")
        40
    }
    func.applyOrElse(value, (_:Any) => println("None"))
    val ts = List[(String,(String,(String,(String,Int))))](
      ("宝安区",("宝安中学",("大数据班",("zhangsan",20)))),
      ("宝安区",("宝安中学",("大数据班",("wangwu",20)))),
      ("宝安区",("宝安中学",("大数据班",("zhaoliu",20))))
    )

    val func2:PartialFunction[(String,(String,(String,(String,Int)))),(String,String)] ={
      case (region,(school,(className,(stuName,age)))) => (school,stuName)
    }
    ts.map(x=>func2(x)).foreach({
      case (x,y) => println(y)
    })
  }
}
